﻿using ETask.Api.Dtos;
using ETask.Api.Services;
using Microsoft.AspNetCore.Mvc;

namespace ETask.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ProjectTaskController : ControllerBase
    {

        private readonly IProjectTaskService _taskService;

        public ProjectTaskController(IProjectTaskService taskService)
        {
            _taskService = taskService;
        }

        [HttpPost("getList")]
        public async Task<IActionResult> GetList([FromBody] ProjectTaskListParams listParams)
        {
            var res = await _taskService.GetListAsync(listParams);
            return Ok(res);
        }

        [HttpPost("addTask")]
        public async Task<IActionResult> AddTask([FromBody] CreateProjectTaskDto createProjectTaskDto)
        {
            var res = await _taskService.CreateAsync(createProjectTaskDto);
            return Ok(ApiResponse.Ok(res));
        }

        [HttpPost("updateTask")]
        public async Task<IActionResult> UpdateTask([FromBody]UpdateProjectTaskDto updateProjectTaskDto)
        {
            var res = await _taskService.UpdateAsync(updateProjectTaskDto.Id, updateProjectTaskDto);
            return Ok(ApiResponse.Ok(res));
        }

        [HttpPost("delById")]
        public async Task<IActionResult> DelTask([FromBody] PrimaryKey key)
        {
            await _taskService.DeleteAsync(key.Id);
            return Ok("删除成功");
        }
    }
}
